'''
	Snake is a publisher subscriber profiler. It records the order and counts
	the number of pubsub calls.
	
	@author: J.H. Donker
	@copyright: Twente University
'''

import wx
from wx.lib.pubsub import Publisher


class Snake:
	'''
		Snake listens to all calls and records everything.
	'''
	def __init__(self):
		'''
			Constructor. Subscribes to all messages.
		'''
		Publisher().subscribe(self.SnakeMethod)
		self.topics = {}
		self.order = []
		
	
		
	def SnakeMethod(self, message):
		'''
			The work horse method. Logs everything.
			
			@param message: The recieved message.
		'''
		self.order.append(message.topic)
		if not self.topics.has_key(message.topic):
			self.topics[message.topic] = 1
		else:
			self.topics[message.topic] =  self.topics[message.topic] + 1
		#self.PrintStats()
		
	def PrintStats(self):
		'''
			Print the stats that where captured.
		'''
		print "Messages"
		print self.order
		print "Sats:"
		print self.topics
		print "Dc:", Publisher.getDeliveryCount(), "Mc:", Publisher.getMessageCount()
